<template>
  <div class="audit-page">
    <el-dialog
      v-model="visibleDialog"
      title="企业认证审核驳回"
      @close="clearData"
      width="600px"
    >
      <div class="audit-content">
        <el-form
          ref="formRef"
          :model="formModel"
          label-width="100px"
          label-position="left"
          :rules="formRules"
        >
          <el-form-item label="驳回原因" prop="reason">
            <el-select
              v-model="formModel.reason"
              placeholder="请选择驳回原因"
              clearable
            >
              <el-option
                v-for="item in rejectReason"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input
              v-model="formModel.remark"
              type="textarea"
              rows="5"
              resize="none"
              placeholder="请输入备注"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div class="my-dialog-footer">
          <el-button @click="cancel"> 取消 </el-button>
          <el-button type="danger" :loading="loading" @click="handleReject"
            >驳回</el-button
          >
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ElMessage } from "element-plus";
const visibleDialog = ref<boolean>(false);
const formModel: any = ref({
  reason: "",
  remark: "",
});
const formRules: any = ref({
  reason: [
    {
      required: true,
      message: "请选择驳回原因",
      trigger: "change",
    },
  ],
});
const rejectReason: any = ref([
  { value: "企业基础信息有误", label: "企业基础信息有误" },
  { value: "企业营业信息有误", label: "企业营业信息有误" },
  { value: "企业联系人信息有误", label: "企业联系人信息有误" },
]);
const loading: any = ref(false);
const formRef: any = ref(null);
const props: any = defineProps({
  ids: {
    type: Array,
    default: [],
  },
});
const emit = defineEmits<{(event: 'rejectSuccess'):void}>();
const open = () => {
  visibleDialog.value = true;
};

// 取消
function cancel() {
  formRef.value?.resetFields();
  visibleDialog.value = false;
}

// 驳回
function handleReject() {
  formRef.value.validate(async (valid: any) => {
    if (valid) {
      loading.value = true;
      let params: any = {
        status: 2,
        ids: props.ids,
        reason: formModel.value.reason,
        remark: formModel.value.remark,
      };
      const res: any = await MyService.account.companyAuth(params);
      if (res.code == 200) {
        ElMessage.success("驳回成功");
        formRef.value?.resetFields();
        emit("rejectSuccess");
        visibleDialog.value = false;
      } else {
        ElMessage.error(res.msg);
      }
      loading.value = false;
    }
  });
}

const clearData = () => {
  formRef.value?.resetFields();
};

defineExpose({
  open,
});
</script>

<style scoped>
.sub-title {
  margin-bottom: 24px;
  font-family: Source Han Sans CN, Source Han Sans CN;
  font-weight: 400;
  font-size: 14px;
  color: #000000;
  line-height: 21px;
  text-align: left;
  font-style: normal;
  text-transform: none;
  padding-left: 14px;
  height: 21px;
  border-left: 2px solid rgba(0, 0, 0, 0.9);
}
.margin-left-16 {
  margin-left: 16px;
}
.form-1 {
  padding-left: 16px;
}
.upload-comp,
.person-cert {
  display: flex;
}
.my-dialog-footer {
  display: flex;
  width: 100%;
  justify-content: end;
}
</style>
